<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>留言板</title>

    <!-- Bootstrap core CSS -->
    <link href="<?php echo __PUBLIC__ ?>/css/bootstrap.min.css" rel="stylesheet">


    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->


    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="http://cdn.bootcss.com/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="./index.php">留言板xxxx</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
        <?php if(isset($_SESSION['username'])){ ?>
          <div class="navbar-form navbar-right">
            <span class='btn btn-success'><?php echo $_SESSION['username'] ?></span>
            <a href="./loginout.php" class="btn btn-success">退出</a>
          </div>

        <?php  }else{ ?>

        
          <form action="./login.php" class="navbar-form navbar-right" role="form" method="post">
            <div class="form-group">
              <input type="text" placeholder="用户名" class="form-control" name="username">
            </div>
            <div class="form-group">
              <input type="password" placeholder="密码" class="form-control" name="password">
            </div>
            <button type="submit" class="btn btn-success">登录</button>
            <a href="./reg.php"  class="btn btn-success">注册</a>
          </form>
        <?php  } ?>
        </div><!--/.navbar-collapse -->
      </div>
    </nav>
    <!-- Main jumbotron for a primary marketing message or call to action -->
    <div class="jumbotron">
      
    </div>

    <div class="container">
      <!-- Example row of columns -->
      <div class="row">
        	<div class="list-group" id="list">
        		<?php foreach ($db as $k => $v) { ?>
				    <div class="list-group-item">
				        <h4 class="list-group-item-heading">
				            <?php echo $v['username'] ?>(<?php echo date('Y-m-d H:i:s',$v['create_time']) ?>)
				        </h4>
				        <p class="list-group-item-text">
				            <?php echo $v['content'] ?>
				        </p>
				        <p class="list-group-item-text" >
				           <a href="./index.php?m=home&c=index&a=del&id=<?php echo $v['id'] ?>" class="btn btn-danger" onclick="if(confirm('确定删除吗')==false){return false;}">删除</a>
				        	<a href="./edit.php?id=<?php echo $v['id'] ?>" class="btn btn-primary">修改</a> 
				        </p>
				        
				    </div>
			    <?php } ?>
			</div>
			<button id="more" class="btn btn-primary btn-lg btn-block">加载更多</button>
			<style type="text/css">
				.col-md-12{
					padding:0px;
					margin-top: 10px;
				}
			</style>
			<form action="./index.php?m=home&c=index&a=add" method="post" class="form-inline col-md-12" role="form">
			  <div class="col-md-12">
				  	<div class="form-group">
				    <label class="sr-only" for="exampleInputEmail2">用户名</label>
				    <input type="text" class="form-control" id="exampleInputEmail2" placeholder="用户名" name="username" value="">
				  </div>
				  <button type="submit" class="btn btn-success">留言</button>
			  </div>
			  <textarea name="content" style="width:100%" class="form-control col-md-12" rows="3"></textarea>
			</form>
        
      </div>

      <hr>

      <footer>
        <p>&copy; Company 2014</p>
      </footer>
    </div> <!-- /container -->


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
    <script src="<?php echo __PUBLIC__ ?>/js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->

    <script type="text/javascript">
	    $(function  () {
	    	page=1;
	    	$('#more').click(function(event) {

	    		page++;
	    		$.ajax({
	    			url: './ajax.php',
	    			type: 'POST',
	    			dataType: 'html',
	    			data: {p:page},
	    		})
	    		.done(function(data) {
	    			// alert(data);
	    			$('#list').append(data);
	    		})
	    		.fail(function(data) {
	    			console.log("error");
	    		})
	    	});
	    })
    </script>
  </body>
</html>
